package com.puchi.sdkdemo.utils

import android.app.Activity
import android.content.Context
import android.os.Build
import android.view.View
import com.puchi.sdkdemo.App



object AllUtlis {

    /**
     * px转dp
     *
     * @param pxValue px值
     * @return dp值
     */
    fun px2dp(pxValue: Float): Int {
        val scale = App.context!!.getResources().getDisplayMetrics().density
        return (pxValue / scale + 0.5f).toInt()
    }

    /**
     * dp转px
     *
     * @param dpValue dp值
     * @return px值
     */
    fun dp2px(dpValue: Float): Int {
        val scale = App.context!!.getResources().getDisplayMetrics().density
        return (dpValue * scale + 0.5f).toInt()
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    fun hideBottomUIMenu(activity: Activity) {

        val window = activity.getWindow()

        val params = window.getAttributes()

        params.systemUiVisibility =
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_FULLSCREEN

        window.setAttributes(params)

        var uiFlags = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE

                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar


                or View.SYSTEM_UI_FLAG_FULLSCREEN) // hide status bar

        if (Build.VERSION.SDK_INT >= 19) {

            uiFlags =
                uiFlags or 0x00001000  //SYSTEM_UI_FLAG_IMMERSIVE_STICKY: hide navigation bars - compatibility: building API level is lower thatn 19, use magic number directly for higher API target level

        } else {

            uiFlags = uiFlags or View.SYSTEM_UI_FLAG_LOW_PROFILE

        }

        activity.getWindow().getDecorView().setSystemUiVisibility(uiFlags)


        /* //隐藏虚拟按键，并且全屏
         if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
             val v = activity!!.window.decorView
             v.systemUiVisibility = View.GONE
         } else if (Build.VERSION.SDK_INT >= 19) {
             //for new api versions.
             val decorView = activity!!.window.decorView
             val uiOptions = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                     or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN)
             decorView.systemUiVisibility = uiOptions
         }
 */
    }
}